package io.renren.modules.sys.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.sys.dao.PurchaseDao;
import io.renren.modules.sys.entity.PurchaseEntity;
import io.renren.modules.sys.service.ProductService;
import io.renren.modules.sys.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;


@Service("purchaseService")
public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity> implements PurchaseService {

    @Autowired
    private ProductService productService;
    @Override
    public PageUtils    queryPage(Map<String, Object> params) {
        Page<PurchaseEntity> page = new Query<PurchaseEntity>(params).getPage();
        page.setRecords(baseMapper.selectList(page , params));
        return new PageUtils(page);
    }
    @Transactional
    @Override
    public void purchaseIn(PurchaseEntity purchase) {
        productService.updateNumber(purchase.getProId(),purchase.getNumber());
        insert(purchase);
    }

}
